package com.example.demo;

import java.util.List;

/**
 * @program: java_base
 * @description:
 * @author: zhouhongtao
 * @happyCreateTime: 2022/02/17 09:16
 */
public class Utils {

    /**
     * 数组交换两个数
     * @param arr
     * @param index
     * @param swapIndex
     */
    public static void swap01(Object[] arr, int index, int swapIndex){
        Object tmp = arr[index];
        arr[index] = arr[swapIndex];
        arr[swapIndex] = tmp;
    }

    /**
     * 数组交换两个数
     * @param list
     * @param index
     * @param swapIndex
     */
    public static void swap02(List list, int index, int swapIndex){
        Object tmp = list.get(index);
        list.set(index, list.get(swapIndex));
        list.set(swapIndex, tmp);
    }

    /**
     *
     * @param arr
     * @param index
     * @param swapIndex
     */
    public static void swap03(int[] arr, int index, int swapIndex){
        arr[index] = arr[index] ^ arr[swapIndex];
        arr[swapIndex] = arr[index] ^ arr[swapIndex];
        arr[index] = arr[index] ^ arr[swapIndex];
    }


}
